<template>
	<div id="addMerchant">

    <div class="flex_head">
      <div class="solid"></div>
      <div class="item_two">
        <el-button type="primary" @click="changeStatus">添加通道</el-button>
      </div>
    </div>
    <el-dialog title="添加通道" :visible.sync="dialogFormVisible" size="tiny">
      <el-form>
        <el-form-item label="通道名" :label-width="formLabelWidth">
          <el-input v-model="form.name" auto-complete="off"></el-input>
        </el-form-item>
        <el-form-item label="编号" :label-width="formLabelWidth">
          <el-input v-model="form.code" auto-complete="off"></el-input>
        </el-form-item>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="addChannel">确 定</el-button>
      </div>
    </el-dialog>
		<el-table :data="channelList" border style="width: 100%" v-loading="loading1">
			<el-table-column prop="id" label="ID">
			</el-table-column>
			<el-table-column prop="name" label="通道名">
			</el-table-column>
      <el-table-column prop="code" label="编号">
      </el-table-column>
			<el-table-column  label="通道开关">
				<template slot-scope="scope">
					<el-button type="primary" size='small' @click="channleStart(scope.row.id)">开启</el-button>
					<el-button type="primary" size="small" @click="channleStop(scope.row.id)">停止</el-button>
				</template>

			</el-table-column>
      <el-table-column  label="修改">
        <template slot-scope="scope">
          <el-button type="text" size='small' @click="reviseChannle(scope.row)">修改</el-button>

        </template>

      </el-table-column>
      <!--<el-table-column  label="提现开关">-->
        <!--<template slot-scope="scope">-->
          <!--<el-button type="primary" size='small' @click="channleStart(scope.row.id)">开启</el-button>-->
          <!--<el-button type="primary" size="small" @click="channleStop(scope.row.id)">停止</el-button>-->
        <!--</template>-->

      <!--</el-table-column>-->
      <!--<el-table-column  label="报件开关">-->
        <!--<template slot-scope="scope">-->
          <!--<el-button type="primary" size='small' @click="channleStart(scope.row.id)">开启</el-button>-->
          <!--<el-button type="primary" size="small" @click="channleStop(scope.row.id)">停止</el-button>-->
        <!--</template>-->

      <!--</el-table-column>-->
			<el-table-column label="商户组管理">
				<template slot-scope="scope">

					<el-button type="text" @click="bussinessGroup(scope.row.id,scope.row.name)">商户组管理</el-button>

				</template>

			</el-table-column>

		</el-table>

	 <!--<div class="block" style="text-align: right;padding-top: 15px;">-->

    <!--<el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"-->
                   <!--:page-size="pageSize" layout="total, prev, pager, next" :total="total">-->
    <!--</el-pagination>-->
  <!--</div>-->
	</div>
</template>

<script>
	import transfer from '../userMange/transfer'
	import merchant from './merchant'
	export default {
		data () {
			return {
				loading1:false,
				dialogVisible2:false,
				dialogVisible: false,
				value2: true,
				channelList:[],
				dialogFormVisible: false,
				formLabelWidth: '80px',
				pageSize:10,
				pageNumber:1,
				total:1,
        form:{
          name:"",
          code:'',

        }
			}
		},
		created(){
			this.getChannelList()
		},
		methods:{
			getChannelList(){
				this.loading1=true;
				let _this = this;
				this.$api.getChannelList().then(function(res){
					if(res.code=='000000'){
						console.log(res.data);
						_this.loading1 = false;
						_this.channelList=res.data;
						_this.total = res.data.length;
            _this.$message.success("获取通道列表成功")
					}
				})
			},
      changeStatus(){
        this.dialogFormVisible=true;
        sessionStorage.setItem("channle id",'');
        this.form.name = '';
        this.form.code = '';
      },

			addChannel(){
				this.dialogFormVisible = false;
				let _this = this;
        let id = sessionStorage.getItem("channle id");
        if(id){
          this.form.id = id;
        }else{
          if(this.form.id){
            delete this.form.id
          }
        }
				this.$api.saveChannel(this.form).then(function(res){
					if(res.code == '000000'){
						_this.$message({
							type:'success',
							message:"保存通道成功"
						});
						_this.getChannelList()
					}
				})
			},
      reviseChannle(row){
        this.dialogFormVisible =true;
        sessionStorage.setItem("channle id",row.id);
        this.form.name = row.name;
        this.form.code = row.code;
//        for(let i in row){
//          for(let j in this.form){
//            if(i == j){
//              this.form[j] = row[i] + ''
//            }
//          }
//        }

      },
			channleStart(id){
				let _this = this;
			   	this.$api.getChannelStart(id).then(res =>{
			   		if(res.code == '000000'){
			   			_this.$message({
							type:'success',
							message:"通道开启成功"

						});
			   		}
			   	})
			},
			channleStop(id){
				let _this = this;
			   	this.$api.getChannelStop(id).then(res =>{
			   		if(res.code == '000000'){
			   			_this.$message({
							type:'success',
							message:"通道关闭成功"

						});
			   		}
			   	})
			},
			bussinessGroup(id,name){
				this.$router.push({
					path:'/merchantMange/businessGroup',
					query:{
						channleId:id,
						channleName:name
					}

				});
				sessionStorage.setItem("channleId",id)
			},
					 handleSizeChange(val) {
        console.log(`每页 ${val} 条`);
      },
      handleCurrentChange(val) {
        this.pageNumber= val;
        this.getChannelList()
      }
		},
		components:{
			"my-transfer":transfer,
			"my-merchant":merchant
		}
	}
</script>

<style>
	.cell {
		text-align: center;
	}
</style>
